package centerberg.game;

import java.awt.Graphics2D;
import java.io.File;

/**
 * Menu for selecting levels.
 * 
 * @author Andreas Svanberg
 */
public class LevelSelectMenu extends Menu
{
    /**
     * Creates a new level select menu.
     */
    public LevelSelectMenu()
    {
        super("Level select");
        
        // Create a button for ever level available
        File levelDirectory = new File("resources/levels");
        for (final File levelFile : levelDirectory.listFiles())
        {
            Button level = new Button(levelFile.getName());
            level.setAction(new Action() {
                public void execute() {
                    MenuSystem.hideMenu();
                    new Thread(new Runnable() {
                        public void run() {
                            LevelLoader.load(levelFile.getPath()).start();
                        }
                    }).start();
                }
            });
            buttons.add(level);
        }
        
        Button back = new Button("Back");
        back.setAction(new Action() {
            public void execute() {
                MenuSystem.goBack();
            }
        });
        buttons.add(back);
    }
    
    /**
     * {@inheritDoc}
     */
    protected int draw(Graphics2D g)
    {
        return 150;
    }
}